#include "kelabeltoast.h"

#include <QTimer>
#include <QFont>
#include <QRectF>

#include "css4kepop.h"

KeLabelToast::KeLabelToast(const QString &text, QWidget *parent)
    : QLabel{text,parent,Qt::Popup}
{

    setAttribute(Qt::WA_TranslucentBackground);
    setWindowFlags(Qt::Popup);//windowFlags() | Qt::FramelessWindowHint |

    setStyleSheet(DefaultQSS_KeLabel);
        // setWindowFlags(Qt::FramelessWindowHint);
    // setWindowOpacity(1);
    // setAttribute(Qt::WA_TranslucentBackground);
    // setAttribute(Qt::WA_TranslucentBackground,true);添加此，整个label背景是黑色
    // border-radius:6px;


    setAlignment(Qt::AlignCenter);
    setAttribute(Qt::WA_TransparentForMouseEvents,true);

}

KeLabelToast::~KeLabelToast()
{

}

void KeLabelToast::showAt(int msec,const QPoint &point)
{
    show();
    move(point);
    // No such slot QLabel::timeoutClose(),.h-file add Q_OBJECT, no works
    // QTimer::singleShot(msec,this,SLOT(KeLabelToast::timeoutClose()));

    QTimer::singleShot(msec,this,&KeLabelToast::timeoutClose);
}

void KeLabelToast::mousePressEvent(QMouseEvent *)
{
    // setAttribute(Qt::WA_NoMouseReplay);
    setVisible(false);

}

void KeLabelToast::timeoutClose()
{
    deleteLater();
}
